package com.zenika.zenbinding.client.renderer;

import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
import com.zenika.zenbinding.client.converter.Converter;
import com.zenika.zenbinding.client.exception.DataException;
import com.zenika.zenbinding.client.feedback.DummyFeedbackManager;
import com.zenika.zenbinding.client.feedback.FeedbackManager;
import com.zenika.zenbinding.client.model.BusinessObject;
import com.zenika.zenbinding.client.model.ValueModel;
import com.zenika.zenbinding.client.util.BeanUtil;

public class LabelRenderer implements Renderer {

	private String property;
	private String style;

	public LabelRenderer(String property) {
		this.property = property;
	}

	public Widget render(BusinessObject object) {
		Label label = new Label();
		if (this.style != null) {
			label.setStyleName(this.style);
		}
		ValueModel model = new ValueModel(object, this.property);
		try {
			Converter converter = BeanUtil.getDefaultConverter(object, this.property);
			model.setConverter(converter);
		} catch (DataException e) {
			e.printStackTrace();
		}
		label.setText(model.getValue());
		return label;
	}

	public Widget render(BusinessObject source, DummyFeedbackManager manager) {
		return this.render(source);
	}

	public void setStyleName(String style) {
		this.style = style;
	}

	public void setFeedbackManager(FeedbackManager manager) {
		// TODO Auto-generated method stub

	}

}
